;;;
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;     http://paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright:  2009
;;;	   Edited:  2009
(DEFUN c:imgbnd ( / );selimgent imgentdat tenslst1 tenslst2)
  (IF (>= (ATOI (SUBSTR (GETVAR "ACADVER") 1 2)) 17)
    (command "_.imageframe" "2")
    (command "_.imageframe" "on")
  )
  (SETQ selimgent (ENTSEL "\nSelect Image for boundary reconstruction. "))
  (IF selimgent
    (SETQ imgentdat (ENTGET (CAR selimgent)))
  )
  (COND
    ((AND imgentdat (EQ (CDR (ASSOC 0 imgentdat)) "IMAGE"))
    (PROGN
      (setq tenslst2 (cdr (member (assoc 91 imgentdat) imgentdat)))
      (IF tenslst2
        (PROGN
          (SETQ imgbnd_lst NIL)
           (ENTMAKE (LIST (CONS 0 "POLYLINE")
                          (CONS 10 (LIST 0 0 0))
                          (CONS 66 1)
                    ) ;_ end of list
           ) ;_ end of entmake
           (FOREACH n tenslst2
             (IF (EQ (CAR n) 14)
               (SETQ imgbnd_lst (APPEND imgbnd_lst (LIST (MAPCAR '(LAMBDA (x) (* x 1 (CADR (ASSOC 11 imgentdat)))) (CDR n)))))
             )
           )
           (SETQ this_y_lst (mapcar 'car imgbnd_lst)
                 this_miny (CAR this_y_lst)
                 this_x_lst (mapcar 'cadr imgbnd_lst)
                 this_minx (CAR this_x_lst)
                 this_base (CDR (ASSOC 10 imgentdat))
           )
           (FOREACH n this_y_lst
             (IF (< n this_miny)
               (SETQ this_miny n)
             )
           )
           (FOREACH n this_x_lst
             (IF (< n this_minx)
               (SETQ this_minx n)
             )
           )
           (SETQ adjbnd_lst (MAPCAR '(LAMBDA (x)
                                       (POLAR
                                         (POLAR this_base 0 (-(CAR x) this_minx))
                                         (* PI 1.5)
                                         (+ (CADR x) this_miny)
                                       )
                                     )
                                     imgbnd_lst
                            )
           )
           (FOREACH n adjbnd_lst
             (ENTMAKE (LIST (CONS 0 "VERTEX")(CONS 10 n)))
           )
           (ENTMAKE (LIST (CONS 0 "SEQEND")))
        )
        (PRINC "\nFailed to find image clip boundary points! ")
      )
    )
     )
    (imgentdat (PRINC (STRCAT "\n" (CDR (ASSOC 0 imgentdat)) " was selected, you must select an IMAGE object! ")))
    (T (PRINC "You must select an IMAGE object! "))
  )
  (IF (>= (ATOI (SUBSTR (GETVAR "ACADVER") 1 2)) 17)
    NIL
    (command "_.imageframe" "off")
  )
  (PRINC)
)